package com.bgt.springboot.first.repository;

import com.bgt.springboot.first.vo.Teacher;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.*;
import java.util.Map;

/**
 * Created by baiguantao on 2017/5/3.
 *  测试复杂的分页多表查询
 */
public class TeacherSpecification extends CommParamsPage implements Specification<Teacher> {

    @Override
    public Predicate toPredicate(Root<Teacher> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
        Map<String ,String> params=this.params;
       //1.混合条件查询
        Path<String> exp1 = root.get("name");
        Path<String> exp2 = root.get("year");
        query.where(cb.like(exp1, "%王%"),cb.equal(exp2, "45"));

       /* Join<Teacher,Student> join=root.join("student",JoinType.INNER);
        Path<String> exp3 = join.get("name");
        cb.like(exp3, "%"+params.get("")+"%");*/
        //2.多表查询
        /*Join<ImTeacher,ImStudent> join = root.join("imStudent", JoinType.INNER);

            Path<String> exp3 = join.get("name");

            return cb.like(exp3, "%jy%");*/
        return query.getRestriction();
    }
}
